/*
 * Phrase_connector.h
 *
 *  Created on: Jun 10, 2011
 *      Author: Mario Hock
 */

#ifndef PHRASE_CONNECTOR_H_
#define PHRASE_CONNECTOR_H_

#include "ariba/ariba.h"
#include "interfaces/Useroutputinterface.h"
#include "Userdatabase.h"
#include "Transport.h"
#include "messages/MeetMessage.h"

#include <ariba_dht/Dht.h>
#include <ariba_dht/DhtAnswerInterface.h>


using namespace std;
using ariba_service::dht::DhtAnswerInterface;

class Phrase_connector : 
    public ariba::CommunicationListener,
    public ariba_service::dht::DhtAnswerInterface,
    public boost::noncopyable
{
public:
  Phrase_connector(Userdatabase& users, ariba::Node& node, Transport& trans);
  virtual ~Phrase_connector();

  // DhtAnswerInterface
  virtual void handle_dht_answer(const std::string& key, const std::vector<std::string>& values);

  // interface to trigger a new meet
  void meet(string phrase);

  
protected:
    /*** CommunicationListener interface ***/
    
    virtual void onMessage(const ariba::DataMessage& msg, const ariba::NodeID& source,
            const ariba::LinkID& lnk = ariba::LinkID::UNSPECIFIED);

    
private:
  ariba::ServiceID serviceID;
  Userdatabase& users;
  ariba::Node& node;
  Transport& trans;
  
  ariba_service::dht::Dht dht;
  
  string pending_invitations;
  bool waiting;
};

#endif /* PHRASE_CONNECTOR_H_ */
